<?php

use yii\db\Migration;

class m171108_060541_rename_classroom extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }

    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->renameColumn('{{%classroom}}','is_group','classroom_group_id');
            $this->alterColumn('{{%classroom}}','classroom_group_id',$this->integer()->comment('班级组id'));
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%classroom}}','classroom_group_id');
        }
    }
}
